package com.cindata

import org.joda.time.DateTime

class DateUtil {
    static GetApiDateShow(String dateStr){
        def date = GetApiDate(dateStr)
        if(!date){
            return ""
        }
        return date.format("yyyy年MM月dd日")
    }
    static GetApiDate(String dateStr){
        if(dateStr == null || dateStr == ""){
            return null
        }
        return Date.parse("yyyy-MM-dd h:m:s",dateStr)
    }

    static GetInputDate(String dateStr){
        def dates = dateStr.toString().replaceAll("[^x00-xff]", "-")
        def rDateStr = dates.toString().substring(0, dates.length() - 1)
        return Date.parse('yyyy-MM-dd', rDateStr)
    }

    static GetDateBeginByDate(Date date){
        DateTime jDate = new DateTime(date)
        DateTime jDateBegin = jDate.withTimeAtStartOfDay()
        return jDateBegin.toDate()
    }

    static GetNextDateBeginByDate(Date date){
        DateTime jDate = new DateTime(date)
        DateTime jDateEnd = jDate.plusDays( 1 ).withTimeAtStartOfDay()
        return jDateEnd.toDate()
    }

    static GetDateBeginByDateStr(String dateStr){
        return GetDateBeginByDate(GetInputDate(dateStr))
    }

    static GetNextDateBeginByDateStr(String dateStr){
        return GetNextDateBeginByDate(GetInputDate(dateStr))
    }
}
